package com.example.demo.retry;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @program: demo
 * @description:
 * @author: zt22328 赵儒定
 * @create: 2022-07-12 13:47
 **/
@Component
public class SpringContextHolder implements ApplicationContextAware {
    private static ApplicationContext context;

    public SpringContextHolder() {
    }

    @Override
    public void setApplicationContext(ApplicationContext context) {
        SpringContextHolder.context = context;
    }

    public static ApplicationContext getApplicationContext() {
        return context;
    }

    public static <T> T getBean(String name) {
        return (T) context.getBean(name);
    }

    public static <T> T getBean(Class clazz) {
        return (T) context.getBean(clazz);
    }
}
